﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Tomahawk.Runtime.Console.Commands
{
    public class HelpCommand : ConsoleCommand
    {
        public override string GetName()
        {
            return "help";
        }

        public override string GetHelp()
        {
            return "Shows help about the available commands";
        }

        public override string Execute(string[] parameters)
        {
            if (parameters.Count() > 1)
            {
                ConsoleCommand consoleCommand;
                commandTable.TryGetValue(parameters[1], out consoleCommand);

                ConsoleComponent.WriteLine("Command " + consoleCommand.GetName() + ":", Color.LightYellow);
                ConsoleComponent.WriteLine("-----------------------------------------", Color.LightYellow);
                ConsoleComponent.WriteLine(consoleCommand.GetHelp(), Color.LightYellow);
            }
            else
            {
                ConsoleComponent.WriteLine("Available commands", Color.LightYellow);
                ConsoleComponent.WriteLine("-----------------------------------------", Color.LightYellow);
                foreach (KeyValuePair<string, ConsoleCommand> command in commandTable)
                {
                    ConsoleCommand consoleCommand = command.Value;
                    ConsoleComponent.WriteLine(consoleCommand.GetName(), Color.LightYellow);
                }
            }
            return "";
        }
    }
}
